package frame.options.simulation.results.sdn.summary;

import java.util.List;

import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import model.components.networks.sdn.SdnNetwork;

@SuppressWarnings("serial")
public class SdnNetworksTable extends JTable
{
	private List< List< SdnNetwork > > sdnNetworksNetworks;
	public List< List< SdnNetwork > > getSdnNetworksNetworks(){ return sdnNetworksNetworks; }
	public void setSdnNetworksNetworks( List< List< SdnNetwork > > sdnNetworksNetworks ){ this.sdnNetworksNetworks = sdnNetworksNetworks; }

	public SdnNetworksTable( List< List< SdnNetwork > > sdnNetworksNetworks )
	{	
		this.setSdnNetworksNetworks( sdnNetworksNetworks );
		
		this.setModel( this.defaultTableModel() );
		this.setEnabled( false );
	}
	
	private DefaultTableModel defaultTableModel()
	{
		DefaultTableModel defaultTableModel = new DefaultTableModel( new String[]{ "<html><b>Network</b></html>", "<html><b>Revenue</b></html>" }, 0 );
		int networksRevenue = 0;
		
		for( List< SdnNetwork > sdnNetworkNetworks: this.getSdnNetworksNetworks() )
		{
			int networkRevenue = 0;
			
			for( SdnNetwork sdnNetworkNetwork: sdnNetworkNetworks )
				networkRevenue += sdnNetworkNetwork.getNetworkRevenue();
			
			networksRevenue += networkRevenue;			
			defaultTableModel.addRow( new Object[]{ "<html><b>" + sdnNetworkNetworks.get( 0 ).getName() + "</b></html>", networkRevenue } );
		}
		
		defaultTableModel.addRow( new Object[]{ "<html><b>Total</b></html>", "<html><b>" + networksRevenue + "</b></html>" } );
		
		return defaultTableModel;
	}
	
}
